/*******************************************************************************
 * Copyright (c) 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package com.takaharabooks.mhp3rd;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.Cursor;
import android.database.SQLException;

public class DB_QuestGallery extends DB_Base
{
	//**********************定数定義**********************
	//***** 数値
	// Version
	// 2011/03/19	ver.4
	// 2011/05/22	ver.6
	// 2011/05/23	ver.7
	public static final int DB_VER = 7;
	//***** 文字列
	// DB名
	public static final String	DB_NAME = "Quest.db";
	// テーブル名
	public static final String	DB_QUEST_TBL_NAME = "tb_quest";
	public static final String	DB_QUEST_MATERIAL_TBL_NAME = "tb_quest_material";
	public static final String	DB_QUEST_MONSTER_TBL_NAME = "tb_quest_monster";
	// 列名
	public static final String	DB_COL_QUEST_ID = "quest_id";
	public static final String	DB_COL_QUEST_CATEGORY = "quest_category";
	public static final String	DB_COL_QUEST_STARS = "quest_stars";
	public static final String	DB_COL_QUEST_KEY_FLAG = "quest_key_flag";
	public static final String	DB_COL_QUEST_KIND = "quest_kind";
	public static final String	DB_COL_QUEST_MAP = "quest_map";
	public static final String	DB_COL_QUEST_MONEY = "quest_money";
	public static final String	DB_COL_QUEST_TRADE_MONEY = "quest_trade_money";
	public static final String	DB_COL_QUEST_TIME = "quest_time";
	public static final String	DB_COL_QUEST_TITLE = "quest_title";
	public static final String	DB_COL_QUEST_PURPOSE = "quest_purpose";
	public static final String	DB_COL_QUEST_MEMO = "quest_memo";
	public static final String	DB_COL_QUEST_MONSTER = "quest_monster";
	public static final String	DB_COL_QUEST_M_ID = "quest_m_id";
	public static final String	DB_COL_QUEST_M_QUEST_ID = "quest_m_quest_id";
	public static final String	DB_COL_QUEST_M_NAME = "quest_m_quest_name";
	public static final String	DB_COL_QUEST_M_RATE = "quest_m_quest_rate";
	public static final String	DB_COL_QUEST_M_NUM = "quest_m_quest_num";
	public static final String	DB_COL_QUEST_MONSTER_ID = "quest_monster_id";
	public static final String	DB_COL_QUEST_MONSTER_QID = "quest_monster_qid";
	public static final String	DB_COL_QUEST_MONSTER_MID = "quest_monster_mid";
	// カテゴリ
	public static final int		QUEST_CATEGORY_VILLEDGE = 1;
	public static final int		QUEST_CATEGORY_PARK_LOWER = 2;
	public static final int		QUEST_CATEGORY_PARK_HIGHER = 3;
	public static final int		QUEST_CATEGORY_EVENT = 4;
	//**********************定数定義**********************

    // 設定情報
    //public Preferences_Setting m_csSetting;
	
	public boolean m_bUpdateFlag = false; 
	
    // DB
    DB_WeakPointGallery m_dbWeakPoint = null;
    
    // クエスト情報変数
    public int m_nQuestNum = 0;
    public int m_nQuestNo[];
    public int m_nQuestCategory[];
    public int m_nQuestStars[];
    public int m_nQuestKey[];
    public int m_nQuestKind[];
    public int m_nQuestMap[];
    public int m_nQuestMoney[];
    public int m_nQuestTradeMoney[];
    public int m_nQuestTime[];
    public String m_strQuestTitle[];
    public String m_strQuestPurpose[];
    public String m_strQuestMemo[];
    public String m_strQuestMonster[];
    
    // 報酬素材
    public int m_nQuestMNum;
    public String m_strQuestMaterialName[];
    public int m_nQuestMaterialRate[];
    public int m_nQuestMaterialNum[];    
    
    // モンスター情報
    public int m_nQuestMonsterNum;
    public int m_nUserID[];
    public String m_strQuestMonsterImgName[];    
    
	// コンストラクタ
	public DB_QuestGallery(Context context) {
		super(context, DB_NAME, DB_VER);
	    // DBアクセスクラス生成
		//m_csDBSql = new DB_BaseOperater(context, DB_NAME_MISSION, DB_VER_MISSION);
        // セッティング情報を準備
        //m_csSetting = new Preferences_Setting(context);

		// データベースを作成
    	if( null == m_dbWeakPoint ){
	        m_dbWeakPoint = new DB_WeakPointGallery(context); 
	        m_dbWeakPoint.InitDB();	                    
    	}
    	
	}
	
	// ＤＢからデータ取得して内部でセット
	public boolean StartDB()
	{
		SetDB(QUEST_CATEGORY_VILLEDGE, 1);
        
        return true;
	}
	
	/*****************************************
	 *  絞込みのデータを取得
	 ****************************************/
    public boolean SetDB(int nCategory, int nStar)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		try{
			String strWhere = String.format( "where %s = %d and %s = %d",
											 DB_COL_QUEST_CATEGORY,		nCategory,
											 DB_COL_QUEST_STARS,		GetStar(nCategory, nStar)
			);
			String strQuery = String.format( "select * from %s %s",
											 DB_QUEST_TBL_NAME,
											 strWhere );
	    	csCur = readDB(strQuery);			
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		m_nQuestNum = csCur.getCount();
		m_nQuestNo = new int[m_nQuestNum];
		m_nQuestCategory = new int[m_nQuestNum];
		m_nQuestStars = new int[m_nQuestNum];
		m_nQuestKey = new int[m_nQuestNum];
		m_nQuestKind = new int[m_nQuestNum];
		m_nQuestMap = new int[m_nQuestNum];
		m_nQuestMoney = new int[m_nQuestNum];
		m_nQuestTradeMoney = new int[m_nQuestNum];
		m_nQuestTime = new int[m_nQuestNum];
	    m_strQuestTitle = new String[m_nQuestNum];
	    m_strQuestPurpose = new String[m_nQuestNum];
	    m_strQuestMemo = new String[m_nQuestNum];
	    m_strQuestMonster = new String[m_nQuestNum];
    	
    	// ガーベジコレクション
    	java.lang.System.gc();

    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<m_nQuestNum; nIndex++){
        	m_nQuestNo[nIndex] = csCur.getInt(0);
        	m_nQuestCategory[nIndex] = csCur.getInt(1);
        	m_nQuestStars[nIndex] = csCur.getInt(2);
        	m_nQuestKey[nIndex] = csCur.getInt(3);
        	m_nQuestKind[nIndex] = csCur.getInt(4);
        	m_nQuestMap[nIndex] = csCur.getInt(5);
        	m_nQuestMoney[nIndex] = csCur.getInt(6);
        	m_nQuestTradeMoney[nIndex] = csCur.getInt(7);
        	m_nQuestTime[nIndex] = csCur.getInt(8);
        	m_strQuestTitle[nIndex] = csCur.getString(9);
        	m_strQuestPurpose[nIndex] = csCur.getString(10);
        	m_strQuestMemo[nIndex] = csCur.getString(11);
        	m_strQuestMonster[nIndex] = csCur.getString(12);
        	csCur.moveToNext();
        }
        csCur.close();
        
        return true;
    }

	/*****************************************
	 *  絞込みのデータを取得
	 ****************************************/
    public boolean SetQuestMaterialDB(int nQuestIndex)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		try{
			String strWhere = "where " + DB_COL_QUEST_M_QUEST_ID + " = " + m_nQuestNo[nQuestIndex];
			String strQuery = String.format( "select * from %s %s",
											 DB_QUEST_MATERIAL_TBL_NAME,
											 strWhere );
	    	csCur = readDB(strQuery);
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		m_nQuestMNum = csCur.getCount();
		m_strQuestMaterialName = new String[m_nQuestMNum];
		m_nQuestMaterialRate = new int[m_nQuestMNum];
		m_nQuestMaterialNum = new int[m_nQuestMNum];
    	
    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<m_nQuestMNum; nIndex++){
        	m_strQuestMaterialName[nIndex] = csCur.getString(2);
        	m_nQuestMaterialRate[nIndex] = csCur.getInt(3);
        	m_nQuestMaterialNum[nIndex] = csCur.getInt(4);
        	csCur.moveToNext();
        }
        csCur.close();
        
        return true;
    }

	/*****************************************
	 *  絞込みのデータを取得
	 ****************************************/
    public boolean SetQuestMonsterDB(int nQuestIndex)
    {
		Cursor csCur;
		// ＤＢからデータの取得
		try{
			String strWhere = String.format("where %s = %s",
					DB_COL_QUEST_MONSTER_QID,	m_nQuestNo[nQuestIndex]
			);
			String strQuery = String.format( "select * from %s %s",
											 DB_QUEST_MONSTER_TBL_NAME,
											 strWhere );
	    	csCur = readDB(strQuery);
		}catch(Exception e){
			// 例外時は何もしない
			return false;
		}
		
		m_nQuestMonsterNum = csCur.getCount();
		m_nUserID = new int[m_nQuestMonsterNum];
		m_strQuestMonsterImgName = new String[m_nQuestMonsterNum];
    	
    	// カーソルを使ってメンバ変数にデータをセット
        csCur.moveToFirst();
        for(int nIndex=0; nIndex<m_nQuestMonsterNum; nIndex++){
        	int nMID = csCur.getInt(2)-1;
        	m_nUserID[nIndex] = nMID;
        	m_strQuestMonsterImgName[nIndex] = m_dbWeakPoint.GetUserMonsterImageIDFromDB(nMID);
        	csCur.moveToNext();
        }
        csCur.close();
        
        return true;
    }

	/*****************************************
	 *  データ数を取得
	 ****************************************/
    public int GetQuestDataNum(){
    	return m_nQuestNum;
    }
	
	/*****************************************
	 *  データ数を取得
	 ****************************************/
    public int GetQuestMaterialDataNum(){
    	return m_nQuestMNum;
    }
	
	/*****************************************
	 *  データ数を取得
	 ****************************************/
    public int GetQuestMonsterDataNum(){
    	return m_nQuestMonsterNum;
    }
	
	/*****************************************
	 *  テーブルＩＤを取得
	 ****************************************/
	public int GetQuestNo(int nIndex)
	{
        return m_nQuestNo[nIndex];
    }
	
	/*****************************************
	 *  クエストタイトルを取得
	 ****************************************/
	public String GetQuestTitleStr(int nIndex)
	{
        return m_strQuestTitle[nIndex];
    }
	
	/*****************************************
	 *  クエストキーを取得
	 ****************************************/
	public int GetQuestKey(int nIndex)
	{
        return m_nQuestKey[nIndex];
    }
	
	/*****************************************
	 *  クエストモンスターを取得
	 ****************************************/
	public String GetQuestMonsterStr(int nIndex)
	{
        return m_strQuestMonster[nIndex];
    }
	
	/*****************************************
	 *  クエストマップを取得
	 ****************************************/
	public String GetQuestMapStr(int nIndex)
	{
        return m_stStrMap[m_nQuestMap[nIndex]-1];
    }
	
	/*****************************************
	 *  クエスト種別を取得
	 ****************************************/
	public String GetQuestKindStr(int nIndex)
	{
        return m_stStrQuestKind[m_nQuestKind[nIndex]-1];
    }
	
	/*****************************************
	 *  成功条件を取得
	 ****************************************/
	public String GetQuestPurpose(int nIndex)
	{
        return m_strQuestPurpose[nIndex];
    }
	
	/*****************************************
	 *  クエスト情報（備考）を取得
	 ****************************************/
	public String GetQuestMemo(int nIndex)
	{
        return m_strQuestMemo[nIndex];
    }
	
	/*****************************************
	 *  報酬金額を取得
	 ****************************************/
	public int GetQuestMoney(int nIndex)
	{
        return m_nQuestMoney[nIndex];
    }
	
	/*****************************************
	 *  契約金額を取得
	 ****************************************/
	public int GetQuestTradeMoney(int nIndex)
	{
        return m_nQuestTradeMoney[nIndex];
    }
	
	/*****************************************
	 *  制限時間を取得
	 ****************************************/
	public int GetQuestTime(int nIndex)
	{
        return m_nQuestTime[nIndex];
    }
	
	/*****************************************
	 *  クエスト素材名を取得
	 ****************************************/
	public String[] GetQuestMaterialName()
	{
        return m_strQuestMaterialName;
    }
	
	/*****************************************
	 *  クエスト素材率を取得
	 ****************************************/
	public int[] GetQuestMaterialRate()
	{
        return m_nQuestMaterialRate;
    }
	
	/*****************************************
	 *  クエスト素材数を取得
	 ****************************************/
	public int[] GetQuestMaterialNum()
	{
        return m_nQuestMaterialNum;
    }
	
	/*****************************************
	 *  モンスターイメージを取得
	 ****************************************/
	public String[] GetQuestMonsterImageName()
	{
        return m_strQuestMonsterImgName;
    }
	
	/*****************************************
	 *  (モンスターに対応する)ユーザーIDを取得
	 ****************************************/
	public int[] GetQuestMonsterUserID()
	{
        return m_nUserID;
    }
	
	
    //データベースオブジェクトを取得する（データベースにアクセスするとDBがない場合は作成される。）  
	public void InitDB(){
		InitDBBase();//DB_Base
		StartDB();
	}
	
	// @Override onCreate
	@Override
	public void onCreate(SQLiteDatabase db)
	{
		InitAllTbl(db);
    }

	// @Override onUpgrade
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		//if(oldVersion <= DB_VER){
			DropAllTbl(db, oldVersion);
			InitAllTbl(db);
		//}
			
		////////////////////////////
		// 全バージョン共通処理
		
		// イメージ情報更新
		//for(int nIndex=0; nIndex<m_stnImageIds.length; nIndex++){
		//	UpdateMonsterImage(db, nIndex, m_stnImageIds[nIndex]);
		//}
		
		m_bUpdateFlag = true;
	}
	
	// ＤＢをすべて破棄します
	public void DropAllTbl(SQLiteDatabase db, int oldVersion)
	{
        String sql = "";  
        // ｸｴｽﾄテーブル削除
        try {
	        sql += "drop table " + DB_QUEST_TBL_NAME;
	        db.execSQL(sql);
    	}catch(SQLException e){
    	}
        // ｸｴｽﾄ素材テーブル削除
        try {
        	sql = "";  
	        sql += "drop table " + DB_QUEST_MATERIAL_TBL_NAME;
	        db.execSQL(sql);
    	}catch(SQLException e){
    	}
        // ｸｴｽﾄモンスターテーブル削除
        try {
        	sql = "";  
	        sql += "drop table " + DB_QUEST_MONSTER_TBL_NAME;
	        db.execSQL(sql);
    	}catch(SQLException e){
    	}
	}
	
	// ＤＢをすべて作成します
	public void InitAllTbl(SQLiteDatabase db)
	{
		// DBクリエイト
		CreateTBLofQuest(db);
		CreateTBLofQuestMaterial(db);
		CreateTBLofQuestMonster(db);
	}
	
	/*****************************************
	 *  ユーザー用モンスターイメージ情報テーブルを作成
	 ****************************************/
	public void CreateTBLofQuest(SQLiteDatabase db)
	{
        String sql = String.format(
        		"create table %s (" +
        		" %s integer primary key, %s integer, %s integer, %s integer, " + 
        		" %s integer, %s integer, %s integer, %s integer, %s integer, " + 
        		" %s text not null, %s text not null, %s text, %s text " + 
        		")",
        		DB_QUEST_TBL_NAME,
        		DB_COL_QUEST_ID,
        		DB_COL_QUEST_CATEGORY,
        		DB_COL_QUEST_STARS,
        		DB_COL_QUEST_KEY_FLAG,
        		DB_COL_QUEST_KIND,
        		DB_COL_QUEST_MAP,
        		DB_COL_QUEST_MONEY,
        		DB_COL_QUEST_TRADE_MONEY,
        		DB_COL_QUEST_TIME,
        		DB_COL_QUEST_TITLE,
        		DB_COL_QUEST_PURPOSE,
        		DB_COL_QUEST_MEMO,
        		DB_COL_QUEST_MONSTER
        );
        db.execSQL(sql);

        // 村クエ情報データ挿入
        InsertQuestForVilledgeInfo(db);
        // 集会浴場下位クエ情報データ挿入
        InsertQuestForParkLowerInfo(db);
        // 集会浴場上位クエ情報データ挿入
        InsertQuestForParkHigherInfo(db);
        // イベント情報データ挿入
        InsertQuestForEventInfo(db);
	}
	
	/*****************************************
	 *  村クエ情報データを挿入
	 ****************************************/
	public void InsertQuestForVilledgeInfo(SQLiteDatabase db)
	{
		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length; nIndex++){
        	nNo = nIndex+1;
        	sql = "";
        	sql += "insert into " + DB_QUEST_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + QUEST_CATEGORY_VILLEDGE + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][0] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][1] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][3] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][4] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][5] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][6] + ", ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][7] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][8] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][9] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo[nIndex][10] + "\' ";
        	sql += ")";
            db.execSQL(sql);
        }		
	}

	/*****************************************
	 *  集会所下位クエ情報データを挿入
	 ****************************************/
	public void InsertQuestForParkLowerInfo(SQLiteDatabase db)
	{
		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + QUEST_CATEGORY_PARK_LOWER + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][0] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][1] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][3] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][4] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][5] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][6] + ", ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][7] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][8] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][9] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkLowerInfo[nIndex][10] + "\' ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  集会所下位クエ情報データを挿入
	 ****************************************/
	public void InsertQuestForParkHigherInfo(SQLiteDatabase db)
	{
		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stStrQuestForParkHigherInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length 
        		+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + QUEST_CATEGORY_PARK_HIGHER + ", ";
        	sql += "" + (Integer.valueOf(DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][0])) + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][1] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][3] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][4] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][5] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][6] + ", ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][7] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][8] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][9] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForParkHigherInfo[nIndex][10] + "\' ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  イベントクエ情報データを挿入
	 ****************************************/
	public void InsertQuestForEventInfo(SQLiteDatabase db)
	{
		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stStrQuestForEventInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length 
	        	+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length
	        	+ DB_DefineData_Quest.m_stStrQuestForParkHigherInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + QUEST_CATEGORY_EVENT + ", ";
        	sql += "" + (Integer.valueOf(DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][0])) + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][1] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][3] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][4] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][5] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][6] + ", ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][7] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][8] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][9] + "\', ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestForEventInfo[nIndex][10] + "\' ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  ユーザー用モンスターイメージ情報テーブルを作成
	 ****************************************/
	public void CreateTBLofQuestMaterial(SQLiteDatabase db)
	{
        String sql = String.format(
        		"create table %s (" +
        		" %s integer primary key, %s integer, %s text not null, " + 
        		" %s integer, %s integer " + 
        		")",
        		DB_QUEST_MATERIAL_TBL_NAME,
        		DB_COL_QUEST_M_ID,
        		DB_COL_QUEST_M_QUEST_ID,
        		DB_COL_QUEST_M_NAME,
        		DB_COL_QUEST_M_RATE,
        		DB_COL_QUEST_M_NUM
        );
        db.execSQL(sql);

        // データ挿入
        InsertQuestMaterialInVilledge(db);
        InsertQuestMaterialInParkLower(db);
        InsertQuestMaterialInParkHigher(db);
        InsertQuestMaterialInEvent(db);
	}
	
	/*****************************************
	 *  クエスト用素材データを挿入（村クエ）
	 ****************************************/
	public void InsertQuestMaterialInVilledge(SQLiteDatabase db)
	{
		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex<DB_DefineData.m_stStrQuestMaterialInfo.length; nIndex++){
        	nNo = nIndex+1;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MATERIAL_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + DB_DefineData.m_stStrQuestMaterialInfo[nIndex][0] + ", ";
        	sql += "\'" + DB_DefineData.m_stStrQuestMaterialInfo[nIndex][1] + "\', ";
        	sql += "" + DB_DefineData.m_stStrQuestMaterialInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData.m_stStrQuestMaterialInfo[nIndex][3] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  クエスト用素材データを挿入（集会浴場下位クエ）
	 ****************************************/
	public void InsertQuestMaterialInParkLower(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length;

		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData.m_stStrQuestMaterialInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MATERIAL_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + Integer.valueOf(DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo[nIndex][0])) + ", ";
        	sql += "\'" + DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo[nIndex][1] + "\', ";
        	sql += "" + DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo[nIndex][3] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  クエスト用素材データを挿入（集会浴場上位クエ）
	 ****************************************/
	public void InsertQuestMaterialInParkHigher(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length;

		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData.m_stStrQuestMaterialInfo.length
        				   + DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MATERIAL_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + Integer.valueOf(DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo[nIndex][0])) + ", ";
        	sql += "\'" + DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo[nIndex][1] + "\', ";
        	sql += "" + DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo[nIndex][3] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  クエスト用素材データを挿入（イベントクエ）
	 ****************************************/
	public void InsertQuestMaterialInEvent(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkHigherInfo.length;

		String sql = "";
        int nNo = 0;
        for(int nIndex=0; nIndex<DB_DefineData_Quest.m_stStrQuestMaterialInEventInfo.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData.m_stStrQuestMaterialInfo.length
			   + DB_DefineData_Park.m_stStrQuestMaterialInParkLowerInfo.length
			   + DB_DefineData_Park.m_stStrQuestMaterialInParkHigherInfo.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MATERIAL_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + Integer.valueOf(DB_DefineData_Quest.m_stStrQuestMaterialInEventInfo[nIndex][0])) + ", ";
        	sql += "\'" + DB_DefineData_Quest.m_stStrQuestMaterialInEventInfo[nIndex][1] + "\', ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestMaterialInEventInfo[nIndex][2] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stStrQuestMaterialInEventInfo[nIndex][3] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
		
	}
	
	/*****************************************
	 *  ユーザー用モンスターイメージ情報テーブルを作成
	 ****************************************/
	public void CreateTBLofQuestMonster(SQLiteDatabase db)
	{
        String sql = String.format(
        		"create table %s (" +
        		" %s integer primary key, %s integer, %s integer " + 
        		")",
        		DB_QUEST_MONSTER_TBL_NAME,
        		DB_COL_QUEST_MONSTER_ID,
        		DB_COL_QUEST_MONSTER_QID,
        		DB_COL_QUEST_MONSTER_MID
        );
        db.execSQL(sql);

        // 村クエデータ挿入
        InsertQuestMonsterInVilledge(db);
        // 集会所下位クエデータ挿入
        InsertQuestMonsterInParkLower(db);
        // 集会所上位クエデータ挿入
        InsertQuestMonsterInParkHigher(db);
        // イベントクエストデータ挿入
        InsertQuestMonsterInEvent(db);
	}
	
	/*****************************************
	 *  モンスターイメージ情報テーブルを挿入（村クエ）
	 ****************************************/
	public void InsertQuestMonsterInVilledge(SQLiteDatabase db)
	{
		String sql = "";
        // データ挿入
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stnQuestMonster.length; nIndex++){
        	nNo = nIndex+1;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MONSTER_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + DB_DefineData_Quest.m_stnQuestMonster[nIndex][0] + ", ";
        	sql += "" + DB_DefineData_Quest.m_stnQuestMonster[nIndex][1] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
	}
	
	/*****************************************
	 *  モンスターイメージ情報テーブルを挿入（下位クエ）
	 ****************************************/
	public void InsertQuestMonsterInParkLower(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length;
		
		String sql = "";
        // データ挿入
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stnQuestMonsterInParkLower.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stnQuestMonster.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MONSTER_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + DB_DefineData_Quest.m_stnQuestMonsterInParkLower[nIndex][0]) + ", ";
        	sql += "" + DB_DefineData_Quest.m_stnQuestMonsterInParkLower[nIndex][1] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
	}
	
	/*****************************************
	 *  モンスターイメージ情報テーブルを挿入（上位クエ）
	 ****************************************/
	public void InsertQuestMonsterInParkHigher(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length;
		
		String sql = "";
        // データ挿入
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stnQuestMonsterInParkHigher.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stnQuestMonster.length
        		+ DB_DefineData_Quest.m_stnQuestMonsterInParkLower.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MONSTER_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + DB_DefineData_Quest.m_stnQuestMonsterInParkHigher[nIndex][0]) + ", ";
        	sql += "" + DB_DefineData_Quest.m_stnQuestMonsterInParkHigher[nIndex][1] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
	}
	
	/*****************************************
	 *  モンスターイメージ情報テーブルを挿入（イベントクエ）
	 ****************************************/
	public void InsertQuestMonsterInEvent(SQLiteDatabase db)
	{
		int nQuestStartID = DB_DefineData_Quest.m_stStrQuestForVilledgeInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkLowerInfo.length
							+ DB_DefineData_Quest.m_stStrQuestForParkHigherInfo.length;
		
		String sql = "";
        // データ挿入
        int nNo = 0;
        for(int nIndex=0; nIndex < DB_DefineData_Quest.m_stnQuestMonsterInEvent.length; nIndex++){
        	nNo = nIndex+1 + DB_DefineData_Quest.m_stnQuestMonster.length
        		+ DB_DefineData_Quest.m_stnQuestMonsterInParkLower.length
        		+ DB_DefineData_Quest.m_stnQuestMonsterInParkHigher.length;
        	sql = "";
        	sql += "insert into " + DB_QUEST_MONSTER_TBL_NAME + " ";
        	sql += "values ( ";
        	sql += "" + nNo + ", ";
        	sql += "" + (nQuestStartID + DB_DefineData_Quest.m_stnQuestMonsterInEvent[nIndex][0]) + ", ";
        	sql += "" + DB_DefineData_Quest.m_stnQuestMonsterInEvent[nIndex][1] + " ";
        	sql += ")";
            db.execSQL(sql);
        }
	}
	
	public int GetStar(int nCategory, int nStar)
	{
		int nRet = nStar;
		if( QUEST_CATEGORY_EVENT == nCategory ){
			//イベントクエスト
			switch(nStar){
			case 1:
			case 2:
			case 3:
				nRet += 2;
				break;
			case 4:
			case 5:
				nRet += 3;
				break;
			default:
				break;
			}
		}else if( QUEST_CATEGORY_PARK_HIGHER == nCategory ){
			// 集会浴場上位
			nRet += 5;
		}
		return nRet;
	}
	
	//////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////
	// ＤＢ上に入れるデフォルトの値

	// クエスト場所
	public String[] m_stStrQuestMainCategory = {
			"村",	"集会浴場 下位", "集会浴場 上位", "イベント"
	};

	// ランク
	public String[] m_stStrQuestStarCategory = {
			"★１",	"★２",	"★３",	"★４",	"★５",	"★６",	"緊急"
	};
	public String[] m_stStrQuestStarCategory2 = {
			"★１",	"★２",	"★３",	"★４",	"★５"
	};
	public String[] m_stStrQuestStarCategory3 = {
			"★６",	"★７",	"★８",	"緊急"
	};
	public String[] m_stStrQuestStarCategory4 = {
			"★３",	"★４",	"★５",	"★７",	"★８"
	};

	// クエスト種別
	public String[] m_stStrQuestKind =
	{
			"<font color=green>採集</font>",
			"<font color=red>討伐</font>",
			"<font color=black>狩猟</font>",
			"<font color=black>連続狩猟</font>",
			"<font color=pink>特殊</font>"
	};
	
	public String[] m_stStrMap =
	{
			// 1-10
			"渓流＜昼＞",	"砂原＜昼＞",	"水没林＜昼＞",	"孤島＜昼＞",	"凍土＜昼＞",
			"渓流＜夜＞",	"砂原＜夜＞",	"水没林＜夜＞",	"孤島＜夜＞",	"凍土＜夜＞",
			// 11-20
			"火山＜昼＞",	"火山＜夜＞",
			"闘技場",
			"大砂漠",
			"小闘技場",
			"溶岩峡谷",
			"極圏",
			"神域",
			"霊峰"
	};
		
}
